/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Trabalho3.RegrasPasswordChecker02;

import Trabalho3.RuleFactory;

/**
 *
 * @author geraldo
 */
public class RegraDescontoLetrasMaiusculasConsecutivas implements RuleFactory{
    private final int FATOR_DESCONTO_MAIUSCULAS_CONSECUTIVAS = -2;
    String password;

    public RegraDescontoLetrasMaiusculasConsecutivas(String password) {
        this.password = password;
    }

    @Override
    public int calcularRegra() {
         return this.SomarMaiusculasConsecutivas()* FATOR_DESCONTO_MAIUSCULAS_CONSECUTIVAS;
    }
    
    public int SomarMaiusculasConsecutivas(){
      
       char[] vetorChar=password.toCharArray();
       int count =0;
        int total=0;
        for (int i=0; i<vetorChar.length;i++){
                    while(i<vetorChar.length && Character.isUpperCase(vetorChar[i])){
                        i++;
                       count++; 
                    }
                    if(count>1){
                        total+=(count-1);
                    }
                    count=0;
                }
        return total;
    }
}
